package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.page.PageQuery2;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.system.domain.TDeviceV2Input;
import com.ruoyi.system.domain.TDeviceV2LineWarnRecord;
import com.ruoyi.system.service.TDeviceV2LineWarnRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liangjiuqing
 * @since 2024-09-27 10:14
 */
@Api(tags = "设备管理-产线预警记录接口")
@RestController
@RequestMapping("/deviceV2LineWarnRecord")
public class TDeviceV2LineWarnRecordController {
    @Autowired
    private TDeviceV2LineWarnRecordService deviceV2LineWarnRecordService;

    @ApiOperation("分页查询产线预警记录列表")
    @GetMapping("/listPageDeviceV2LineWarnRecords")
    public ResultEntity<IPage<TDeviceV2LineWarnRecord>> listPageDeviceV2LineWarnRecords(DeviceV2LineWarnRecordPageQuery deviceV2LineWarnRecordPageQuery) {
        Page<TDeviceV2LineWarnRecord> page = deviceV2LineWarnRecordService.page(deviceV2LineWarnRecordPageQuery.buildPage(),
                Wrappers.<TDeviceV2LineWarnRecord>lambdaQuery()
                        .eq(deviceV2LineWarnRecordPageQuery.getProjectId() != null, TDeviceV2LineWarnRecord::getProjectId, deviceV2LineWarnRecordPageQuery.getProjectId())
                        .orderByDesc(TDeviceV2LineWarnRecord::getCreateTime));
        return ResultEntity.createSuccess(page);
    }

    @ApiOperation("新增或修改产线预警记录数据")
    @PostMapping("/saveOrUpdateDeviceV2LineWarnRecord")
    public ResultEntity<Void> saveOrUpdateDeviceV2LineWarnRecord(@Validated @RequestBody TDeviceV2LineWarnRecord deviceV2LineWarnRecord) {
        deviceV2LineWarnRecordService.saveOrUpdate(deviceV2LineWarnRecord);
        return ResultEntity.createSuccess(null);
    }

    @ApiOperation("批量删除产线预警记录数据")
    @GetMapping("/removeDeviceV2LineWarnRecordByIds/{ids}")
    public ResultEntity<Void> removeDeviceV2LineWarnRecordByIds(@ApiParam(value = "主键ID，逗号分隔", required = true) @PathVariable List<Long> ids) {
        deviceV2LineWarnRecordService.removeByIds(ids);
        return ResultEntity.createSuccess(null);
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    static class DeviceV2LineWarnRecordPageQuery extends PageQuery2 {
        @ApiModelProperty("项目id")
        private Long projectId;
    }

}
